//
//  BRankListMineCell.m
//  DistributorAB
//
//  Created by LZY on 2019/9/29.
//  Copyright © 2019 主事丫环. All rights reserved.
//

// B级经销商排行榜我的排名cell

#import "BRankListMineCell.h"
#import "ZYLookLeaderboardModel.h"

@interface BRankListMineCell ()
@property (nonatomic, strong) UILabel *lblRank;//排名
@property (nonatomic, strong) UILabel *lblAddress;//地址
@property (nonatomic, strong) UILabel *lblMoney;//金额
@end

@implementation BRankListMineCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupViewAction];
    }
    return self;
}
#pragma mark - 界面布局方法
- (void)setupViewAction{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [UIColor clearColor];
    
    UIView *viewBg = [[UIView alloc] initWithFrame:CGRectMake(0, 11, kScreen_Width, 79)];
    viewBg.backgroundColor = kColorWithHex(0xffffff);
    [self.contentView addSubview:viewBg];
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:viewBg.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(20, 20)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = viewBg.bounds;
    maskLayer.path = maskPath.CGPath;
    viewBg.layer.mask = maskLayer;
    
    UIImageView *ivMine = [[UIImageView alloc] initWithFrame:CGRectMake((kScreen_Width - 100) / 2.0, 5, 100, 29)];
    ivMine.image = imgname(@"rank_mine_icon");
    [self.contentView addSubview:ivMine];
    
    UIImageView *ivRank = [UIImageView new];
    ivRank.image = imgname(@"rank_mine_rank");
    [self.contentView addSubview:ivRank];
    UIImageView *ivAddress = [UIImageView new];
    ivAddress.image = imgname(@"rank_mine_address");
    [self.contentView addSubview:ivAddress];
    UIImageView *ivMoney = [UIImageView new];
    ivMoney.image = imgname(@"rank_mine_money");
    [self.contentView addSubview:ivMoney];
    _lblRank = [UILabel new];
    _lblRank.textColor = kColorWithHex(0x333333);
    _lblRank.textAlignment = NSTextAlignmentLeft;
    _lblRank.font = [UIFont systemFontOfSize:18];
    [self.contentView addSubview:_lblRank];
    _lblAddress = [UILabel new];
    _lblAddress.textColor = kColorWithHex(0x333333);
    _lblAddress.textAlignment = NSTextAlignmentLeft;
    _lblAddress.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:_lblAddress];
    _lblMoney = [UILabel new];
    _lblMoney.textColor = kColorWithHex(0x333333);
    _lblMoney.textAlignment = NSTextAlignmentLeft;
    _lblMoney.font = [UIFont systemFontOfSize:16];
    [self.contentView addSubview:_lblMoney];
    
    CGFloat lblWidth = (kScreen_Width - 68 - 30 * 3) / 3.0;
    
    [ivRank mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.contentView.mas_leading).offset(34);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-14);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    [_lblRank mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(ivRank.mas_centerY);
        make.leading.equalTo(ivRank.mas_trailing);
        make.size.mas_equalTo(CGSizeMake(lblWidth, 30));
    }];
    [ivAddress mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.lblRank.mas_trailing);
        make.centerY.equalTo(ivRank.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    [_lblAddress mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(ivRank.mas_centerY);
        make.leading.equalTo(ivAddress.mas_trailing);
        make.size.mas_equalTo(CGSizeMake(lblWidth, 30));
    }];
    [ivMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.lblAddress.mas_trailing);
        make.centerY.equalTo(ivRank.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(30, 30));
    }];
    [_lblMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(ivRank.mas_centerY);
        make.leading.equalTo(ivMoney.mas_trailing);
        make.size.mas_equalTo(CGSizeMake(lblWidth, 30));
    }];
    
    UIView *viewLine = [[UIView alloc] initWithFrame:CGRectMake(0, 89, kScreen_Width, 1)];
    viewLine.backgroundColor = kColorWithHex(0xffbe00);
    [self.contentView addSubview:viewLine];
}
#pragma mark - 界面数据更新
- (void)setModel:(ZYLookLeaderboardModel *)model{
    _model = model;
    if (model) {
        _lblRank.text = [self numberToString:model.rank_no];
        _lblAddress.text = [NSString stringWithFormat:@"%@",model.area_name];
        _lblMoney.text = [self numberChangeUnit:model.earning];        
    }
}
+ (CGFloat)defaultHeight{
    return 90.0;
}
#pragma mark - 数字处理
- (NSString *)numberToString:(double)number{
    if (number > 9) {
        return [NSString stringWithFormat:@"%.0f",number];
    }else{
        return [NSString stringWithFormat:@"0%.0f",number];
    }
}
//单位换算
- (NSString *)numberChangeUnit:(double)number{
    if (number > 9999) {
        return [NSString stringWithFormat:@"%.2fw",number / 10000.0];
    }else{
        return [NSString stringWithFormat:@"%.2f",number];
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
